// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _HTTPPROTOCOL_HH_
#define _HTTPPROTOCOL_HH_
#include "Protocol.hh"

#include <string>


/// this class will retrieve files on http server
/// using cURL library.
class HttpProtocol : public Protocol {
private:
  static size_t memoryRecord(void* ptr, size_t size, size_t nb, void* stream);
  static size_t streamRead(void *ptr, size_t size, size_t nmemb, void *stream);
  static size_t memoryRead(void *ptr, size_t size, size_t nmemb, void *stream);
  static size_t nullOut(void* ptr, size_t size, size_t nb, void* stream);
  void* destPtr;
  size_t pos;
public:
  HttpProtocol();
  HttpProtocol(const HttpProtocol& protocol);
  virtual void downloadDataFile(const std::string& sourceURI,
                                const Credential& credential);

  virtual void downloadDataFile(const std::string& sourceURI,
                                const std::string& path,
                                const Credential& credential);

  virtual void downloadDataFile(const std::list<std::string>& sourceURIs,
                                const std::list<Credential>& credentials);

  virtual void downloadDataFile(const std::list<std::string>& sourceURIs,
                                const std::string& path,
                                const std::list<Credential>& credentials);

  virtual void downloadDataMemory(const std::string& sourceURI,
                                  void* const dest,
                                  const Credential& credential);

  virtual void downloadDataMemory(const std::string& sourceURI,
                                  void** dest,
                                  size_t* size,
                                  const Credential& credential);

  virtual void downloadDataMemory(const std::list<std::string>& sourceURIs,
                                  void* const dest,
                                  const std::list<Credential>& credentials);

  virtual void downloadDataMemory(const std::list<std::string>& sourceURIs,
                                  void** dest,
                                  size_t* size,
                                  const std::list<Credential>& credentials);

  virtual void uploadDataFile(const std::string& destinationURI,
                              const std::string& path,
                              const Credential& credential);

  virtual void uploadDataMemory(const std::string& destinationURI,
                                void* const src,
                                size_t      src_size,
                                const Credential& credential);
};

#endif
